import axios from 'axios'
import {Dialog} from "vant";
import {getToken} from "@/utils/auth";


// 创建axios实例
const service = axios.create({
  baseURL: 'http://121.4.48.40:8090/', // api的base_url
  timeout: 10000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
    config.headers['Authorization'] = getToken()
  return config
}, error => {
  // Do something with request error
  console.log(error) // for debug
})
service.interceptors.response.use(
    response => {
      if (response.data.code !== "200") {
          if (response.data.code === 401) {
              return response
          }else {
              Dialog.alert({
                  title: '错误',
                  message: response.data.message,
              }).then(() => {
                  // on close
              });
          }

      }
      else {
          return response.data
      }
    }
)
export default service
